/**
 * 
 */
package com.hsd.znsh.validator;

import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author zhailiang
 *
 */
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = Phone.PhoneValidator.class)
public @interface Phone {
	
	String message();

	Class<?>[] groups() default { };

	Class<? extends Payload>[] payload() default { };

	class PhoneValidator implements ConstraintValidator<Phone, String> {

		private String regex;

		@Override
		public void initialize(Phone phone) {
			regex="^[1][34578][0-9]{9}$";
		}

		@Override
		public boolean isValid(String value, ConstraintValidatorContext context) {
			if(value.matches(regex)) return true;
			return false;
		}

	}

}
